﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using FONCREAGROINTEGRAL.Models;

namespace FONCREAGROINTEGRAL.Controllers
{
    public class periodicidadingresoController : Controller
    {
        public SistIntFoncreagroEntities entidades = new SistIntFoncreagroEntities();
        //
        // GET: /periodicidadingreso/

        public ActionResult Index()
        {
            int start = Convert.ToInt32(Request.QueryString["start"]);
            int limit = Convert.ToInt32(Request.QueryString["limit"]);

            string nombre = Convert.ToString(Request.QueryString["query"]);

            var query = entidades.PERIODICIDADINGRESOes
                .Where(a => a.IdPeriodicidadIngreso >= 1);
            if (!String.IsNullOrEmpty(nombre))
            {
                query = query.Where(a => (a.NomPeriodicidadIngreso).ToUpper().Contains(nombre.ToUpper()));
            }
            var result = (from a in query.OrderBy(a => a.NomPeriodicidadIngreso).Skip(start).Take(limit).ToList()
                          select new
                          {
                              IdPeriodicidadIngreso = a.IdPeriodicidadIngreso,
                              NomPeriodicidadIngreso = a.NomPeriodicidadIngreso,
                          }).ToList();

            return Json(new { grid = result, total = query.Count() }, JsonRequestBehavior.AllowGet);
        }

        //
        // GET: /periodicidadingreso/Details/5

        public ActionResult Details(int id)
        {
            return View();
        }

        //
        // GET: /periodicidadingreso/Create

        public ActionResult Create()
        {
            return View();
        } 

        //
        // POST: /periodicidadingreso/Create

        [HttpPost]
        public ActionResult Create(FormCollection collection)
        {
            try
            {
                // TODO: Add insert logic here

                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }
        
        //
        // GET: /periodicidadingreso/Edit/5
 
        public ActionResult Edit(int id)
        {
            return View();
        }

        //
        // POST: /periodicidadingreso/Edit/5

        [HttpPost]
        public ActionResult Edit(int id, FormCollection collection)
        {
            try
            {
                // TODO: Add update logic here
 
                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }

        //
        // GET: /periodicidadingreso/Delete/5
 
        public ActionResult Delete(int id)
        {
            return View();
        }

        //
        // POST: /periodicidadingreso/Delete/5

        [HttpPost]
        public ActionResult Delete(int id, FormCollection collection)
        {
            try
            {
                // TODO: Add delete logic here
 
                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }
    }
}
